﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HelfenHelfen.Logic.Interfaces;
using HelfenHelfen.DataAccess.Interfaces;
using HelfenHelfen.DataAccess.Factories;

namespace HelfenHelfen.Logic
{
    public class MessageLogic : IMessageLogic
    {
        public IEnumerable<DataAccess.Entities.Message> GetMessagesForUser(Guid userGuid)
        {
            IMessageDataAccess da = DataAccessFactory.CreateMessageDataAccess();
            var msgs = da.GetMessages(userGuid);

            foreach (var item in msgs)
            {
                da.SetMessageUnread(item.MessageGUID, false);
            }
            return msgs;
        }

        public void SendMessage(DataAccess.Entities.Message message)
        {
            IMessageDataAccess da = DataAccessFactory.CreateMessageDataAccess();
            message.IsUnread = true;
            da.Create(message);
        }


        public void DeleteMessage(Guid messageGUID)
        {
            IMessageDataAccess da = DataAccessFactory.CreateMessageDataAccess();
            da.Delete(messageGUID);
        }


        public int GetMessageCountForUser(Guid userGuid)
        {
            IMessageDataAccess da = DataAccessFactory.CreateMessageDataAccess();
            return da.GetMessageCount(userGuid);
        }
    }
}
